package com.hqyj.shop.controller;

import com.hqyj.shop.pojo.GoodsZhl;
import com.hqyj.shop.service.GoodsServiceZhl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping(path = "/shopZhl")
public class GoodsControllerZhl {

    @Autowired
    private GoodsServiceZhl goodsServiceZhl;
    @RequestMapping("/goods")
    public String queryAll(ModelMap modelMap){
        List<GoodsZhl> goodsList = goodsServiceZhl.goodsQueryAll();
//        System.out.println(goodsList);
        System.out.println("------");
        modelMap.put("goodsList", goodsList);
        return "shopZhl";
    }

    @RequestMapping("/delete")
    public String delById(int goodsId){

        System.out.println(goodsId);
//        goodsId = modelMap.getAttribute(id);
        goodsServiceZhl.deleteById(goodsId);
        return "redirect:/shopZhl/goods";
    }

    @RequestMapping("/edit")
    public String updateOne(GoodsZhl goodsZhl, ModelMap modelMap){
        goodsServiceZhl.updateOne(goodsZhl);
        return "redirect:/shopZhl/goods";
    }
    @RequestMapping("/insert")
    public String insertAll(GoodsZhl goodsZhl, ModelMap modelMap){
        goodsServiceZhl.insertOne(goodsZhl);

        return "redirect:/shopZhl/goods";
    }
}
